<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <title>火灾报警监控系统</title>
    <style>
        body, html {
            margin: 0;
            padding: 0;
            height: 100%;
            width: 100%;
            background: url('background.jpg') no-repeat center center fixed; /* 添加背景图 */
            background-size: cover; /* 使背景图覆盖整个页面 */
            font-family: Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: flex-start;
            box-sizing: border-box;
        }

        body::before {
            content: "";
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: inherit;
            opacity: 0.5; /* 降低背景图的透明度，使内容更清晰 */
            z-index: -1; /* 确保背景图在内容下方 */
        }

        h1 {
            margin: 10px 0;
            text-align: center;
            color: #333;
            width: 100%; /* 确保标题占满宽度 */
        }

        #display-panel {
            width: 50%; /* 将宽度调整为原来的1/2 */
            display: flex;
            flex-direction: column;
            justify-content: flex-start;
            align-items: center;
            background-color: rgba(255, 255, 255, 0.8); /* 使用半透明的背景颜色 */
            border: 1px solid #ccc;
            border-radius: 5px;
            padding: 10px;
            margin-right: 20px; /* 使两部分之间有适当的间距 */
        }

        #video-container {
            width: 100%;
            border: 1px solid #ccc;
            border-radius: 5px;
            padding: 10px;
            background-color: white;
            height: 480px;
        }

        iframe {
            width: 100%;
            height: 100%;
            border: none;
        }

        #fire-detection {
            width: 100%; /* 保持原来的宽度 */
            margin-top: 20px;
            height: 60px; /* 增加栏框高度 */
            background-color: rgba(255, 255, 255, 0.8); /* 使用半透明的背景颜色 */
        }

        #control-panel {
            width: 20%;
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            height: 480px;
            align-items: center;
            background-color: rgba(255, 255, 255, 0.8); /* 使用半透明的背景颜色 */
            border: 1px solid #ccc;
            border-radius: 5px;
            padding: 10px;
            margin-left: 20px; /* 使两部分之间有适当的间距 */
        }

        button {
            width: 100%;
            padding: 15px 30px;
            font-size: 16px;
            margin-bottom: 10px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            color: white;
            background-color: #333;
            transition: background-color 0.3s ease;
        }

        button:hover {
            background-color: #555;
        }

        input[type="text"] {
            width: 100%;
            padding: 10px;
            font-size: 24px; /* 增加字体大小 */
            margin-bottom: 10px;
            border: 1px solid #ccc;
            border-radius: 5px;
            height: 100%; /* 让输入框占满栏框高度 */
            box-sizing: border-box;
            background-color: rgba(255, 255, 255, 0.8); /* 使用半透明的背景颜色 */
        }
    </style>
</head>

<body>
    <div id="display-panel">
        <h1>火灾报警监控系统</h1>
        <div id="video-container">
            <iframe src="http://192.168.10.1:8080/?action=stream" title="嵌入的网页"></iframe>
        </div>
        <div id="fire-detection">
            <input type="text" id="textbox" readonly placeholder="异常情况，火灾警告">
        </div>
    </div>
    <div id="control-panel">
        <h1>控制操作</h1>
        <button id="trigger-alarm-button">触发警报</button>
        <button id="toggle-buzzer-button">蜂鸣器开关</button>
        <button id="exit-button">退出</button>
    </div>

    <script>
        const triggerAlarmButton = document.getElementById('trigger-alarm-button');
        const toggleBuzzerButton = document.getElementById('toggle-buzzer-button');
        const textbox = document.getElementById('textbox');
        const exitButton = document.getElementById('exit-button');

        let buzzerOn = false; // 用于记录蜂鸣器的状态

        // 触发警报按钮按下事件
        triggerAlarmButton.addEventListener('mousedown', function () {
            fetch('/cgi-bin/set_gpio.cgi?gpio=557&value=1')
                .then(response => response.text())
                .then(data => console.log(data));
        });

        // 触发警报按钮松开事件
        triggerAlarmButton.addEventListener('mouseup', function () {
            fetch('/cgi-bin/set_gpio.cgi?gpio=557&value=0')
                .then(response => response.text())
                .then(data => console.log(data));
        });

        // 蜂鸣器开关按钮点击事件
        toggleBuzzerButton.addEventListener('click', function () {
            fetch('/cgi-bin/get_gpio.cgi?gpio=557')
                .then(response => response.text())
                .then(currentValue => {
                    const newValue = currentValue.trim() === '1' ? '0' : '1';
                    buzzerOn = newValue === '1'; // 更新蜂鸣器状态
                    return fetch('/cgi-bin/set_gpio.cgi?gpio=557&value=' + newValue)
                })
                .then(response => response.text())
                .then(data => console.log(data));
        });

        // 监听 gpio558 的值
        function checkGpio558() {
            fetch('/cgi-bin/get_gpio.cgi?gpio=558')
                .then(response => response.text())
                .then(data => {
                    if (data.trim() === '0') {
                        textbox.style.color = 'red'; // 设置文本颜色为红色
                        textbox.value = "异常情况，火灾警告";
                        if (!buzzerOn) {
                            fetch('/cgi-bin/set_gpio.cgi?gpio=557&value=1')
                                .then(response => response.text())
                                .then(data => console.log(data));
                            buzzerOn = true; // 更新蜂鸣器状态
                        }
                    } else {
                        if (textbox.value === "异常情况，火灾警告") {
                            textbox.value = "";
                            textbox.style.color = ''; // 恢复默认颜色
                        }
                    }
                });
        }

        setInterval(checkGpio558, 1000); // 每秒检查一次

        // 退出按钮点击事件
        exitButton.addEventListener('click', function () {
            window.close();
        });
    </script>
</body>

</html>
